import Vue from "vue";
import VueRouter from "vue-router";
// 注册组件
import Reg from "@/views/reg"
// 登录组件
import Login from "@/views/login"
// 首页组件
import Home from "@/views/home"
// 用户
import appUsers from "@/views/appUsers"
// 商品
import appGoods from "@/views/appGoods"
// 订单
import appOrders from "@/views/appOrders"

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: "/reg",
    name: "reg",
    component: Reg
  },
  {
    path: "/login",
    name: "login",
    component: Login,
    meta: {//元信息
      permission: false //不需要拦截
    }
  },
  {
    path: "/home",
    name: "home",
    component: Home,
    redirect: "/home/users",
    // 子路由
    children: [
      {
        path: "users",
        name: "users",
        component: appUsers,
        meta: {
          title: '用户管理'
        }
      },
      {
        path: "goods",
        name: "goods",
        component: appGoods,
        meta: {
          permission: true,//需要拦截
          title: '商品管理'
        }
      },
      {
        path: "orders",
        name: "orders",
        component: appOrders,
        meta: {
          title: '订单管理'
        }
      }
    ]
  }
];

const router = new VueRouter({
  routes,
  mode: "history"  //去除路径后的#号
});

export default router;
